package com.theyeasy.dvmini.execption;




import com.theyeasy.dvmini.enums.ResultsEnum;
import com.theyeasy.dvmini.utils.ValidateUtils;

import java.util.Collection;


public class RpcException extends RuntimeException{

	
private static final long serialVersionUID = 1L;
	
	/**
	 * 成功
	 */
	public static final int C_000 = 0;
	
	/**
	 * 失败
	 */
	public static final int C_001 = -1;
	
	/**
	 * 参数格式错误
	 */
	public static final int C_002 = -2;
	
	/**
	 * 异常
	 */
	public static final int C_003 = -3;
	
	/**
	 * 请重新登录
	 */
	public static final int C_004 = -4;
	
	public static final int C_PAY = -9;

	private int code;
	
	private String message;

	
    public String getMessage() {
        return message;
    }

    
    public void setMessage(String message) {
        this.message = message;
    }

    public RpcException() {
		super();
	}

	public RpcException(String message) {
	    setMessage(message);
	}

	public RpcException(Throwable cause) {
		super(cause);
	}

	public RpcException(String message, Throwable cause) {
	    super(cause);
	    setMessage(message);
	}

	public RpcException(int code) {
		super();
		this.code = code;
	}

	public RpcException(int code, String message, Throwable cause) {
		this(message, cause);
		this.code = code;
	}

	public RpcException(int code, String message) {
		this(message);
		this.code = code;
	}

	public RpcException(int code, Throwable cause) {
		this(cause);
		this.code = code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public int getCode() {
		return code;
	}
	
	public RpcException(ResultsEnum each){
	   this(each.getCode(),each.getMessage());
	}
	
	public static void isNull(Integer str, String msg) throws RpcException {
		if(ValidateUtils.isNull(str))
			throw new RpcException(RpcException.C_002, msg);
	}
	
	public static void isNull(String str, String msg) throws RpcException {
		if(ValidateUtils.isNull(str))
			throw new RpcException(RpcException.C_002, msg);
	}
	
	public static void isNull(Collection<?> collection, String msg) throws RpcException {
		if(ValidateUtils.isNull(collection))
			throw new RpcException(RpcException.C_002, msg);
	}
	
	public static void isTrue(boolean expression, String msg) throws RpcException {
		if(!expression)
			throw new RpcException(RpcException.C_002, msg);
	}
}
